package cn.portx.report;

import java.sql.Connection;
import java.sql.SQLException;

import org.hibernate.Session;
import org.springframework.orm.hibernate5.SessionFactoryUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.bdf3.jpa.JpaUtil;

import cn.portx.entity.Order;

@Component
public class BuildinDatasource implements com.bstek.ureport.definition.datasource.BuildinDatasource {

	@Override
	@Transactional(readOnly = true)
	public Connection getConnection() {
		Session session = JpaUtil.getEntityManager(Order.class).unwrap(Session.class);
		try {
			Connection conn = SessionFactoryUtils.getDataSource(session.getSessionFactory()).getConnection();
			return conn;
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public String name() {
		return "ReportBuildinDataSource";
	}

}
